/*
 * @Author: xiaosihan
 * @Date: 2025-08-24 10:00:00
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2025-11-07 00:00:58
 */
import Api from './Api';

// 一次性事件表单数据类型
export interface OneTimeEventData {
    eventName: string;
    sqlStatement: string;
    executeAt: string;
}

// 周期性事件表单数据类型
export interface RecurringEventData {
    eventName: string;
    sqlStatement: string;
    startTime: string;
    intervalValue: number;
    intervalUnit: string;
    endTime?: string;
    comment?: string;
}

// MySQL事件类型
export interface MySqlEvent {
    Db: string;
    Name: string;
    Body: string;
    Definer: string;
    ExecuteAt: string;
    IntervalField: string;
    IntervalValue: string;
    Created: string;
    Status: 'ENABLED' | 'DISABLED' | 'SLAVESIDE_DISABLED';
    OnCompletion: string;
    Originator: number;
    CharacterSetClient: string;
    CollationConnection: string;
    DatabaseCollation: string;
}

// 事件调度器状态类型
export interface EventSchedulerStatus {
    event_scheduler: 'ON' | 'OFF' | 'DISABLED';
}

class MySqlEventApi extends Api {
    constructor() {
        super();
    }

    // 获取所有事件
    event_events(data: any = {}) {
        return this._post("get_events", data);
    }

    // 获取事件调度器状态
    event_status(data: any = {}) {
        return this._post("get_event_status", data);
    }

    // 开启事件调度器
    event_start_scheduler(data: any = {}) {
        return this._post("write_event_scheduler", data);
    }

    // 关闭事件调度器
    event_stop_scheduler(data: any = {}) {
        return this._post("write_event_scheduler_off", data);
    }

    // 创建一次性事件
    event_create_one_time(data: any) {
        return this._post("write_event", data);
    }

    // 创建周期性事件
    event_create_recurring(data: any) {
        return this._post("write_event_recurring", data);
    }

    // 启用事件
    event_enable(data: any) {
        return this._post("write_event_enable", data);
    }

    // 禁用事件
    event_disable(data: any) {
        return this._post("write_event_disable", data);
    }

    // 删除事件
    event_drop(data: any) {
        return this._post("del_event", data);
    }
}

const mysqlEventApi = new MySqlEventApi();
export default mysqlEventApi;